<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * 微信门店基本信息表
 */
class CreateWxStore extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //微信门店基本信息表
        Schema::create('wx_store_bases', function (Blueprint $table) {
            $table->increments('sid')->comment('门店ID');
            $table->string('business_name', 100)->default('')->comment('门店名称');
            $table->string('branch_name', 100)->default('')->comment('branch_name');
            $table->string('province', 50)->default('')->comment('所在省份');
            $table->string('city', 50)->default('')->comment('所在城市');
            $table->string('district', 50)->default('')->comment('所在地区');
            $table->string('address', 200)->default('')->comment('详细街道地址');
            $table->string('telephone', 200)->default('')->comment('门店电话,可多个,使用英文分号间隔');
            $table->string('longitude', 30)->default('')->comment('地理位置经度(腾讯)');
            $table->string('latitude', 30)->default('')->comment('地理位置纬度(腾讯)');
            //门店图片放在photo表中
            $table->string('recommend', 250)->default('')->comment('推荐品');
            $table->string('special', 200)->default('')->comment('特色服务');
            $table->string('credential', 50)->default('')->comment('经营资质证件号');
            //营业执照放在photo表中
            $table->mediumText('introduction')->nullable()->comment('商户简介');
            $table->string('open_time', 20)->default('')->comment('营业时间');
            $table->string('avg_price', 20)->default('')->comment('人均价格');
            $table->mediumText('card_id')->nullable()->comment('卡券id列表');
            $table->softDeletes();
            $table->timestamps();
        });
        //服务号门店信息
        Schema::create('wx_store_pois', function (Blueprint $table) {
            $table->increments('sid')->comment('门店ID');
            $table->unsignedInteger('poi_id')->default(0)->comment('微信端门店ID');
            $table->string('categories', 200)->default('')->comment('门店类型');
            $table->tinyInteger('offset_type')->default(0)->comment('坐标类型');
            $table->unsignedTinyInteger('available_state')->default(0)->comment('门店是否可用状态');
            $table->unsignedTinyInteger('update_status')->default(0)->comment('扩展字段是否正在更新中');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['poi_id','deleted_at'],'index1');
        });
        //腾讯地图门店信息（创建门店是第一次创建，添加是第一次门店审核通过后）
        Schema::create('wx_store_mappois', function (Blueprint $table) {
            $table->increments('sid')->comment('门店ID');
            $table->unsignedInteger('poi_id')->default(0)->comment('微信端门店ID');
            $table->string('categories', 200)->default('')->comment('门店类型，和服务号一致');
            $table->string('districtid', 50)->default('')->comment('腾讯地图拉取省市区信息接口返回的id');
            $table->string('map_poi_id' , 20)->default('')->comment('从腾讯地图换取的位置点id');
            $table->unsignedInteger('audit_id')->default(0)->comment('审核单id');
            $table->unsignedTinyInteger('audit_status')->default(1)->comment('审核状态（0：审核通过，1：审核失败）');
            $table->string('audit_remark', 200)->default('')->comment('审核备注，对应sh_remark字段');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['poi_id','deleted_at'],'index1');
        });
        //小程序门店信息
        Schema::create('wx_store_wxas', function (Blueprint $table) {
            $table->increments('sid')->comment('门店ID');
            $table->unsignedInteger('poi_id')->default(0)->comment('微信端门店ID');
            $table->unsignedInteger('mapid')->default(0)->comment('腾讯地图的map_poi_id');
            $table->string('company_name', 100)->default('')->comment('主体名字');
            $table->string('categories', 200)->default('')->comment('门店类型，和服务号一致');
            $table->unsignedInteger('audit_id')->default(0)->comment('审核单id');
            $table->unsignedTinyInteger('audit_status')->default(1)->comment('审核状态（0：审核通过，1：审核失败）');
            $table->string('audit_remark', 200)->default('')->comment('审核备注，对应reason字段');
            $table->unsignedTinyInteger('is_upgrade')->default(0)->comment('0 表示创建门店1：表示是补充门店');
            $table->unsignedTinyInteger('upgrade_status')->default(0)->comment('迁移状态');
            $table->string('upgrade_comment', 100)->default('')->comment('迁移驳回的理由');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['poi_id','deleted_at'],'index1');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('wx_store_bases');
        Schema::dropIfExists('wx_store_pois');
        Schema::dropIfExists('wx_store_mappois');
        Schema::dropIfExists('wx_store_wxas');
    }
}
